(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.popup.ppfEffectiveSettingViewController', ppfEffectiveSettingViewController);
	ppfEffectiveSettingViewController.$inject = [ '$scope', '$q', '$uibModalInstance', 'Constants', 'dialogsModule', 'gridService', 'modalService', 'layoutConfig' , 'authService', 'ajaxServiceFactory', 'validatorConfig', 'ppfEffectiveSettingService'];
	function ppfEffectiveSettingViewController($scope, $q, $uibModalInstance, Constants, dialogsModule, gridService, modalService, layoutConfig, authService, ajaxServiceFactory, validatorConfig, ppfEffectiveSettingService) {
		var ctrl = this, log = $scope.loggerFactory.getLogger("ppfEffectiveSettingViewController"), ajaxService = ajaxServiceFactory.buildAjaxService({
			getApEffectiveSettingData : {
				url : 'do/cda/ppfCommunity/effectiveSetting',
				method : 'post'
			},
		});
		ctrl.dialogsModule = dialogsModule;
//		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.ppfEffectiveSetting = {};
		ctrl.formName = "ppfEffectiveSettingForm";
		
		ctrl.init = function() {
			// init int
//			ppfEffectiveSettingService.initProfInt($scope, ctrl);
//			ppfEffectiveSettingService.initProfCostOfFundInt($scope, ctrl);
			// init pastdue
			ppfEffectiveSettingService.initProfPastdue($scope, ctrl, layoutConfig);
			// init fee
			ppfEffectiveSettingService.initProfFee($scope, ctrl, layoutConfig);
			// init Settlement Instruction
			ppfEffectiveSettingService.initProfSetlinst($scope, ctrl, layoutConfig);
			//
			ppfEffectiveSettingService.initGeneral($scope, ctrl).then(function() {
				// init data
				var params = ctrl.dialogsModule.params.ppfCommunity;
				ajaxService.getApEffectiveSettingData(params).then(function(response) {
					var initPpfEffectiveSetting = response.data || {};
					initPpfEffectiveSetting.prodSubtypeExtProperty = ctrl.dialogsModule.params.prodSubtypeExtProperty;
					ppfEffectiveSettingService.initLayoutConfigAndModel($scope, ctrl, initPpfEffectiveSetting, layoutConfig);
				});
			});
		};
		
		ctrl.close = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['close'] || dialogsModule.btnCallback['close']() !== false) {
				$uibModalInstance.dismiss();
			}
		};
		
	}
})(angular);
